﻿var options = {
	autoclose: true,
	locale: 'ru'
};

function updateLoginField() {
	var lastName = $("#LastName").val();
	var firstName = $("#FirstName").val();
	var middleName = $("#MiddleName").val();

	var result = lastName + "_";
	if (firstName !== "" && firstName !== "undefined" && firstName.length > 0) {
		result += firstName.substr(0, 1);
	}

	if (middleName !== "" && middleName !== "undefined" && middleName.length > 0) {
		result += middleName.substr(0, 1);
	}

	$("#Login").val(result);
}

$(document).ready(function () {

    $.validator.methods.range = function (value, element, param) {
        var globalizedValue = value.replace(".", ",");
        return this.optional(element) || (globalizedValue >= param[0] && globalizedValue <= param[1]);
    }

    $.validator.methods.number = function (value, element) {
        return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:[\s\.,]\d{3})+)(?:[\.,]\d+)?$/.test(value);
    }

    $("#DateBirth").datepicker(options);
    $("#StartWorkDate").datepicker(options);

    $("#LastName, #FirstName, #MiddleName").on("keyup", function () {
        updateLoginField();
    });

    $("#Salary").inputmask({ 'mask': "9{0,},9{0,2}", greedy: false });
});
